<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Library\PrintingOptions\PrintingOptions;
use App\Models\Invoices;
use App\Rep\EmployeeRep;
use Illuminate\Http\Request;

class Employee extends Controller
{
    //员工管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new EmployeeRep();
    }

    /**
     * 获取员工列表
     * @param Request $request
     */
    public function getEmployeeList(Request $request){
        $params = $request->all();
        $data = $this->rep->getEmployeeListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 添加员工
     * @param Request $request
     */
    public function createEmployee(Request $request){
        $params = $request->all();
        $data = $this->rep->createEmployeeRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 删除员工
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delEmployee(Request $request){
        $params = $request->all();
        $data = $this->rep->delEmployeeRep($params);
        return re($data['code']);
    }

    /**
     * 获取员工列表通过工种ID
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getEmployeeListByJobTypeID(Request $request){
        $params = $request->all();
        $data = $this->rep->getEmployeeListByJobTypeIDRep($params);
        return re(0,$data,'success');
    }

    /**
     * 员工查询可领取订单
     */
    public function searchPensionableOrderChild(Request $request){
        $params = $request->all();
        $data = $this->rep->searchPensionableOrderChildRep($params);
        return re(0,$data,'success');
    }

    /**
     * 员工领取订单
     */
    public function drawOrderChild(Request $request){
        $params = $request->all();
        $data = $this->rep->drawOrderChildRep($params);
        $order_child = $data['data']->toArray();
        $list = Invoices::where('is_show',1)->orderBy('sort','asc')->get();

        $pritingOptions = new PrintingOptions();
        $array = $pritingOptions->getOrderInvoices($list,$order_child);

//        $array = [];
//        $res = [
//            'title'=>'接单单据',
//            'qr_code'=>json_encode(["order_id"=>$order_child['order_id'],"order_child_id"=>$order_child['id']]),
//            'order_number'=>$order_child['order']['order_number'],
//            'customer_name'=>$order_child['order']['customer']['customer_name'],
//            'order_date'=>$order_child['order']['order_date'],
//            'delivery_date'=>$order_child['order']['delivery_date'],
//            'serial_number'=>$order_child['order']['serial_number'],
//            'emergency_procedure'=>$order_child['order']['emergency_procedure'],
//            'model_number'=>$order_child['order']['model_number']['model_number'],
//            'specification_id'=>$order_child['order']['specification']['specification'],
//            'color'=>$order_child['order']['color']['color'],
//            'direction'=>$order_child['order']['direction'],
//            'remark'=>$order_child['order']['remark'],
//            'draw_time'=>$order_child['draw_time'],
//            'employee_user'=>$order_child['employee']['employee_name'],
//            'employee_user_id'=>$order_child['employee_user_id'],
//            'job_type'=>$order_child['job_type']['job_type'],
//        ];
//        foreach($list as $k=>$v){
//            $array[$k]['field'] = $v->field;
//            $array[$k]['size'] = $v->size;
//            $array[$k]['field_name'] = $v->field_name;
//            $array[$k]['field'] = $v->field;
//            $array[$k]['value'] = $res[$v->field];
//        }

        return re($data['code'],$array,$data['msg']);
    }

    /**
     * 提交订单
     */
    public function submitOrderChild(Request $request){
        $params = $request->all();
        $data = $this->rep->submitOrderChildRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    public function submitOrderChildByDayin(Request $request){
        $params = $request->all();
        $data = $this->rep->submitOrderChildByDayinRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }


    /**
     * 查询已完成订单
     * @param Request $request
     */
    public function searchCompletedOrUnfinishedOrderChild(Request $request){
        $params = $request->all();
        $data = $this->rep->searchCompletedOrUnfinishedOrderChildRep($params);
        return re(0,$data,'success');
    }


}
